#!/usr/bin/python

#
# MMK (Makefile Maker)
# (c) 2012 Stefan Gehr, Guillermo Janner
# Version 1.0
#

import sys


class MMK:
	
	#Constructor
	def __init__(self, aufgabe, code):
		self.makefile = open("Makefile", "w+")
		self.aufgabe = aufgabe
		self.code = code

	#Create makefile
	def create(self):
		self.makefile.write("CC=gcc\n")
		self.makefile.write("CFLAGS=-Wall -Werror -std=c99 -pedantic -D_XOPEN_SORUCE=600\n\n")
		self.makefile.write(".PHONY: all clean\n\n")
		if aufgabe > 0:
			self.makefile.write("PDIR=/proj/i4sp2/pub/aufgabe"+self.aufgabe+"\n\n")
		self.makefile.write("all: "+self.code+"\n\n")
		self.makefile.write(self.code+": "+self.code+".o \n\t$(CC) $(CFLAGS) -o $@ $^\n\n")
		self.makefile.write("clean:\n\trm -f "+self.code+" *.o\n\n")
		self.makefile.write(self.code+".o: "+self.code+".c \n\n")


aufgabe = 0
code = "0"
if len(sys.argv) == 2:
	code = sys.argv[1]
elif len(sys.argv) == 3:
	code = sys.argv[1]
	aufgabe = sys.argv[2]
else:
	print "Falsche Paramter!\n"
	sys.exit()

test = MMK(aufgabe, code)
test.create()
